<link rel="stylesheet" href="/assets/home/css/poster.css">


    <header class="mui-bar mui-bar-nav mui-bar-nav-bg">
        <a id="icon-menu" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">推广海报</h1>
    </header>

    <div class="content">
        <div class="poster">
            <img id="poster" src="{$AutoLogin.poster ? $AutoLogin.poster : ''}" />
        </div>


        <div class="link">
            <input type="text" id="url" value="{$url}" readonly >
            <button class="btn mui-btn-primary" type="button" id="copy-btn" onclick="cpbtn()">点击复制</button>
        </div>

        <div class="update">
            <button class="mui-btn mui-btn-success" type="button" id="update">更新海报</button>
        </div>
    </div>

    <script>
        var update = document.getElementById('update')
        var poster = document.getElementById('poster').getAttribute('src')
        //更新
        update.onclick = function(){
            $.ajax({
                type : 'POST',
                dataType : 'json',
                success:(success) =>
                {   
                    mui.toast(success.msg)

                    if(success.code){

                        $("#poster").prop('src',success.data.poster)
                    }
                }
            })
        }
        
        //如果没有海报地址，就默认触发点击事件
        if(!poster)
        {
            update.onclick();
        }
        
        //复制
        async function cpbtn()
        {
            var url =document.getElementById('url')
            url.select()
            document.execCommand("copy",false);
        }
    </script>